package com.zoweunion.mechanic.controller;

import com.github.pagehelper.PageInfo;
import com.zoweunion.mechanic.entity.TSSsOrderCheckDeployServerEntity;
import com.zoweunion.mechanic.model.ResponseBean;
import com.zoweunion.mechanic.service.TSSsOrderCheckDeployServerService;
import com.zoweunion.mechanic.util.MyException;
import com.zoweunion.mechanic.util.constants.Constants;
import com.zoweunion.mechanic.util.task.CarDataAbnormalTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;



/**
 * 考核分数配置
 *
 * @author xp
 * @email 17688825585@163.com
 * @date 2020-07-13 17:01:46
 */
@RestController
@RequestMapping("/tsssordercheckdeployserver")
public class TSSsOrderCheckDeployServerController extends BaseController {
    @Autowired
    private TSSsOrderCheckDeployServerService tSSsOrderCheckDeployServerService;

    @Autowired
    private CarDataAbnormalTask carDataAbnormalTask;

    /**
     * 列表
     */
    @GetMapping("/tSSsOrderCheckDeployServerList")
    public ResponseBean tSSsOrderCheckDeployServerList(@RequestParam Map<String, Object> params, HttpServletRequest request)  throws MyException{
        params.put("s_id", getCurrentUser(request).getS_id());
        params.put("user_id", getCurrentUser(request).getId());
        PageInfo info = tSSsOrderCheckDeployServerService.queryPage(params);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", info);
    }

    /**
     * 新增
     */
    @PostMapping("/tSSsOrderCheckDeployServerInsertUpdate")
    public ResponseBean tSSsOrderCheckDeployServerInsertUpdate(@RequestBody TSSsOrderCheckDeployServerEntity params,
                                             HttpServletRequest request) {

        params.getEntityList().forEach(item->{
            if (item.getId()!=null){
                tSSsOrderCheckDeployServerService.updateById(item);
            }else {
                try {
                    item.setSId(getCurrentUser(request).getS_id());
                } catch (MyException e) {
                    e.printStackTrace();
                }
                tSSsOrderCheckDeployServerService.save(item);
            }
        });
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 查询配置表
     */
    @GetMapping("/tSSsOrderCheckDeployInfo")
    public ResponseBean tSSsOrderCheckDeployInfo(@RequestParam Map<String, Object> params, HttpServletRequest request)  throws MyException{
        params.put("s_id", getCurrentUser(request).getS_id());
        params.put("user_id", getCurrentUser(request).getId());
        List<TSSsOrderCheckDeployServerEntity> info =
                tSSsOrderCheckDeployServerService.tSSsOrderCheckDeployInfo(params);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", info);
    }


    //waterTemperatureTask
    @GetMapping("/test")
    public void ss(@RequestParam Map<String, Object> params, HttpServletRequest request)  throws MyException{
        carDataAbnormalTask.waterTemperatureTask();
    }


}
